import { IMTableType } from "@/types/table";
import { DrawerFormStateType } from "./type";
export const operateType = ref<any>("");
export const tableActiveKey = ref(0);
export const tabPower = reactive([true, true]);
export const defaultTabsActiveKey = reactive<any>([0, 0]);
export const defaultUserDetailLoading = toRefs(
  reactive<any>([false, false, false, false])
);
export const queryParams = reactive<{
  [propName: string]: any;
}>({});
export const defaultColumns = reactive([
  [
    {
      title: getProxyT("base.index"),
      dataIndex: "index",
      key: "index",
    },
    {
      title: getProxyT("table126"),
      dataIndex: "order_number",
      key: "order_number",
    },
    {
      title: getProxyT("table217"),
      dataIndex: "create_time",
      key: "create_time",
      customRender: ({ text }: any) => getTimeByZone(text),
    },
    {
      title: getProxyT("table133"),
      dataIndex: "order_type",
      key: "order_type",
    },
    {
      title: getProxyT("table218"),
      dataIndex: "order_status",
      key: "order_status",
    },
    {
      title: getProxyT("table137"),
      dataIndex: "pay_platform",
      key: "pay_platform",
    },
    {
      title: computed(() => `${$t("table219")}(USDT)`),
      dataIndex: "amount",
      key: "amount",
    },
    {
      title: getProxyT("table159"),
      dataIndex: "user_info",
      key: "user_info",
    },
    {
      title: getProxyT("base.action"),
      key: "action",
    },
  ],
  [
    {
      title: getProxyT("base.index"),
      dataIndex: "index",
      key: "index",
    },
    {
      title: getProxyT("table126"),
      dataIndex: "order_number",
      key: "order_number",
    },
    {
      title: getProxyT("table217"),
      dataIndex: "withdraw_time",
      key: "withdraw_time",
    },
    {
      title: getProxyT("table133"),
      dataIndex: "order_type",
      key: "order_type",
    },
    {
      title: getProxyT("table220"),
      dataIndex: "status",
      key: "status",
    },
    {
      title: computed(() => `${$t("table219")}(USDT)`),
      dataIndex: "withdraw_amount",
      key: "withdraw_amount",
    },
    {
      title: getProxyT("table137"),
      dataIndex: "pay_type",
      key: "pay_type",
    },

    {
      title: getProxyT("table159"),
      dataIndex: "user_info",
      key: "user_info",
    },
    {
      title: getProxyT("base.action"),
      key: "action",
    },
  ],
]);

export let columns = reactive<IMTableType[]>([
  ...defaultColumns[tableActiveKey.value],
]);
export const merchantMap = ref<any>([]);
export const incomeTradeTypeMap = ref<any>([]);
export const payTradeTypeMap = ref<any>([]);
export const payTypeMap = ref<any>([]);
export const orderStatusMap = ref<any>([]);
export const defaultSearchList = reactive([
  [
    {
      label: getProxyT("table126"),
      type: "input",
      model: "order_number",
      allowClear: true,
      placeholder: getProxyT("placeholder177"),
    },
    {
      label: getProxyT("table133"),
      type: "select",
      model: "order_type",
      placeholder: getProxyT("placeholder153"),
      searchClass: "search-item-width-150",
      allowClear: true,
      options: incomeTradeTypeMap,
    },
    {
      label: getProxyT("table217"),
      // showTime: { format: "HH:mm:ss" },
      type: "rangePicker",
      model: "start_end",
      placeholder: computed(() => [$t("base.startTime"), $t("base.endTime")]),
      // format: "YYYY-MM-DD HH:mm:ss",
      format: "YYYY-MM-DD",
    },
    {
      label: getProxyT("table137"),
      type: "select",
      model: "pay_platform_id",
      placeholder: getProxyT("placeholder94"),
      searchClass: "search-item-width-150",
      allowClear: true,
      options: payTypeMap,
    },
    {
      label: getProxyT("table159"),
      type: "input",
      model: "buy_user",
      allowClear: true,
      placeholder: computed(() => `${$t("placeholder178")}ID`),
    },
  ],
  [
    {
      label: getProxyT("table126"),
      type: "input",
      model: "order_number",
      allowClear: true,
      placeholder: getProxyT("placeholder177"),
    },
    {
      label: getProxyT("table133"),
      type: "select",
      model: "order_type",
      placeholder: getProxyT("placeholder152"),
      allowClear: true,
      options: payTradeTypeMap,
    },
    {
      label: getProxyT("table217"),
      // showTime: { format: "HH:mm:ss" },
      showTime: { format: "YYYY-MM-DD" },
      type: "rangePicker",
      model: "start_end",
      placeholder: computed(() => [$t("base.startTime"), $t("base.endTime")]),
      // format: "YYYY-MM-DD HH:mm:ss",
      format: "YYYY-MM-DD",
    },
    {
      label: getProxyT("table137"),
      type: "select",
      model: "pay_platform_id",
      placeholder: getProxyT("placeholder94"),
      searchClass: "search-item-width-150",
      allowClear: true,
      options: payTypeMap,
    },
    {
      label: getProxyT("table159"),
      type: "input",
      model: "withdraw_user",
      allowClear: true,
      placeholder: computed(() => `${$t("placeholder178")}ID`),
    },
  ],
]);

export const searchList = ref<any>(defaultSearchList[tableActiveKey.value]);
export const drawerTitle = ref("");
export const defaultDrawerColumns = reactive([
  [
    {
      title: getProxyT("table130"),
      dataIndex: "level",
      key: "level",
    },
    {
      title: getProxyT("table125"),
      dataIndex: "member_name",
      key: "member_name",
    },
    {
      title: computed(() => `${$t("table131")}(USDT)`),
      dataIndex: "price",
      key: "price",
    },
    {
      title: getProxyT("table117"),
      dataIndex: "indate",
      key: "indate",
    },
    {
      title: getProxyT("table129"),
      dataIndex: "expire_time",
      key: "expire_time",
    },
    {
      title: getProxyT("table132"),
      dataIndex: "status",
      key: "status",
    },
  ],
  [
    {
      title: computed(() => `${$t("table221")}ID`),
      dataIndex: "level",
      key: "level",
    },
    {
      title: computed(() => `${$t("table222")}(USDT)`),
      dataIndex: "amount",
      key: "amount",
    },
  ],
  [
    {
      title: getProxyT("table223"),
      dataIndex: "contract_no",
      key: "contract_no",
    },
    {
      title: getProxyT("table224"),
      dataIndex: "name",
      key: "name",
    },
    {
      title: getProxyT("table225"),
      dataIndex: "type",
      key: "type",
    },
    {
      title: computed(() => `${$t("table226")}(USDT)`),
      dataIndex: "amount",
      key: "amount",
    },
    {
      title: getProxyT("table117"),
      dataIndex: "validity_period",
      key: "validity_period",
    },
    {
      title: getProxyT("table129"),
      dataIndex: "end_time",
      key: "end_time",
    },
    {
      title: getProxyT("table227"),
      dataIndex: "status",
      key: "status",
    },
  ],
  [
    {
      title: computed(() => `${$t("table228")}ID`),
      dataIndex: "level",
      key: "level",
    },
    {
      title: computed(() => `${$t("table229")}(USDT)`),
      dataIndex: "amount",
      key: "amount",
    },
    {
      title: computed(() => `${$t("table230")}(USDT)`),
      dataIndex: "actual_order_amount",
      key: "actual_order_amount",
    },
    {
      title: getProxyT("table231"),
      dataIndex: "auditor",
      key: "auditor",
    },
  ],
]);

export const defaultOrderType = reactive<any>([null, [1, 4], [2], [3]]);
export const defaultDrawerDataSource = reactive<any>([[], [], [], []]);
export const drawerInstance = ref<any>(null);
export const drawer_disable_ok_button = ref(false);
export const drawerVisible = ref(false);
export const defaultTabsOptions = reactive([[], []]);
export const drawerFormState: any = reactive({});
export const defaultFormState: Array<DrawerFormStateType> = [
  {
    order_number: undefined,
    order_type: undefined,
    order_status: undefined,
    create_time: undefined,
    payment_time: undefined,
    origin_type: undefined,
    third_order_number: undefined,
    pay_type: undefined,
    phone_number: undefined,
    user_info: {},
    member_info: {},
    channel_name: undefined,
    pay_time: undefined,
    contract_info: {
      sign_user_phone_number: undefined,
      name: undefined,
      start_time: undefined,
      contract_pdf: undefined,
      attachment_file: undefined,
      sign_user_info: {},
      send_user_info: {},
    },
    withdrawal_order_number: undefined,
  },
  {},
];
export const resetFormState = (formState) => {
  const currentFormState = defaultFormState[tableActiveKey.value];
  initObjAttr(formState, currentFormState);
};
resetFormState(drawerFormState);
watch([() => tabPower[0], () => tabPower[1]], (newArrayState) => {
  if (newArrayState.some((item) => item === true))
    initObjAttr(columns, defaultColumns[tableActiveKey.value]);
  if (newArrayState.every((item) => item === false)) initObjAttr(columns, []);
});
